package mvc.command.update
{
	import air.update.ApplicationUpdaterUI;
	import air.update.events.UpdateEvent;
	
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.control.CairngormEventDispatcher;
	
	import mvc.control.AirUpdateEvent;

	public class CheckUpdateCmd implements ICommand
	{
		private var _updater:ApplicationUpdaterUI;

		public function execute(event:CairngormEvent):void
		{
			_updater = new ApplicationUpdaterUI();
			_updater.updateURL = "http://air-armory.googlecode.com/files/update.xml";
			_updater.isCheckForUpdateVisible = false;
			_updater.addEventListener(UpdateEvent.INITIALIZED, function(event:UpdateEvent):void
				{
					(event.target as ApplicationUpdaterUI).checkNow();
				});
			_updater.addEventListener(UpdateEvent.DOWNLOAD_COMPLETE, function(event:UpdateEvent):void
				{
					CairngormEventDispatcher.getInstance().dispatchEvent(
						new AirUpdateEvent(AirUpdateEvent.BACKUP_USER_DB));
				});
			_updater.initialize();
		}
	}
}